class fatReq{
    constructor(opts) {
      this.cfg = {
        baseURL: '',
        timeout: 120000
      }
      this.opts = opts;
    }
    async req({url, ...config}) {
      let cfg = {url, ...config};
      if(this.hooks.before){
        cfg = this.hooks.before(cfg) || cfg;
      }
  
      const {res, abort} = await this.fetchMore(cfg);
      let data = await res.json();
      if(this.hooks.after){
        data = this.hooks.after(data) || data;
      }
  
      return {data, abort};
    },
    async fetchMore(url, opts = {}) {
      const { timeout = this.cfg.timeout } = opts;
    
      if(opts.params){
        url += ('?' + new URLSearchParams(opts.params));
      }
      if(opts.data){
        opts.body = JSON.stringify(opts.data);
        delete opts.data;
      }
      
      const abort = new AbortController();
      const id = setTimeout(() => abort.abort(), timeout);
    
      url = this.cfg.baseURL + url;
    
      const res = await fetch(url, {
        ...opts,
        signal: abort.signal  
      });
    
      clearTimeout(id);
    
      return {res, abort};
    }
  }
  
  export default const fReq = {
      create(opts){
        return new FatReq(opts)
      }
  }